@namespace SwashbucklerDiary.Rcl.Components
@inherits CardComponentBase<DiaryModel>

<MCard Class="diary-card elevation-sm-2--active"
       OnClick="HandeOnClick"
       Elevation="0"
       Ripple="false"
       Rounded="@("lg")"
       @oncontextmenu="OpenMenu"
       __internal_preventDefault_oncontextmenu>
    <MListItem Dense>
        <MListItemContent>
            <div class="d-flex align-center">
                @if (TimeFormat is not null)
                {
                    var splits = Value.CreateTime.ToString(TimeFormat).Split(' ');
                    <div class="text--secondary d-flex flex-wrap">
                        @foreach (var item in splits)
                        {
                            bool isFirst = splits.FirstOrDefault() == item;
                            <span class="@($"mr-2 {(isFirst ? "" : "text-caption")}")"
                                  style="@(isFirst ? "font-size:1.1rem;" : "")">
                                @item
                            </span>
                        }
                    </div>
                }

                <div class="d-flex flex-shrink-0">
                    @if (!string.IsNullOrEmpty(weatherIcon))
                    {
                        <MIcon Class="diary-card-icon mr-2"
                               Style="font-size:20px;">
                            @weatherIcon
                        </MIcon>
                    }

                    @if (!string.IsNullOrEmpty(moodIcon))
                    {
                        <MIcon Class="diary-card-icon mr-2"
                               Style="font-size:20px;">
                            @moodIcon
                        </MIcon>
                    }

                    @if (DiaryCardListOptions.Template && Value.Template && Value.Id == DiaryCardListOptions.DefaultTemplateId)
                    {
                        <MChip Small>
                            @I18n.T("Defalut")
                        </MChip>
                    }
                </div>
            </div>
        </MListItemContent>
        <MListItemAction @onclick:stopPropagation="true">
            @if (Value.Top)
            {
                <MIcon Style="width:36px;">vertical_align_top</MIcon>
            }

            @if (Value.Template)
            {
                <MIcon Style="width:36px;">space_dashboard</MIcon>
            }

            <MButton @attributes="activatorAttributes"
                     Icon="true"
                     OnClick="OpenMenu">
                <MIcon Class="@MenuIconClass">
                    keyboard_arrow_down
                </MIcon>
            </MButton>
        </MListItemAction>
    </MListItem>
    <MDivider Class="mx-4"></MDivider>
    <MListItem ThreeLine>
        <MListItemContent>
            @if (!string.IsNullOrEmpty(Value.Title))
            {
                <MListItemTitle Class="diary-card__title">
                    @Value.Title
                </MListItemTitle>
            }

            @if (Markdown)
            {
                <SimpleMarkdownPreview Value="@text"
                                       Style="pointer-events:none;"
                                       Patch="false">
                </SimpleMarkdownPreview>
            }
            else
            {
                <MListItemSubtitle>@text</MListItemSubtitle>
            }


        </MListItemContent>
    </MListItem>
    @if (Value.Tags is not null && Value.Tags.Count > 0)
    {
        <div class="px-4 diary-card__tags">
            <div style="white-space: nowrap;width:100%;overflow-x:hidden;">
                @foreach (var item in Value.Tags)
                {
                    <MChip @key="item.Id"
                           Class="mr-2">
                        @(item.Name)
                    </MChip>
                }
            </div>
        </div>
    }
    @if (!string.IsNullOrEmpty(Value.Location))
    {
        <div class="diary-card__location">
            <DiaryInfoButton Icon="location_on"
                             Text="@(Value.Location)">
            </DiaryInfoButton>
        </div>
    }
</MCard>
